package com.hskj.controller;

import com.hskj.dto.ResponseDTO;
import com.hskj.exception.MyException;
import com.hskj.model.Category;
import com.hskj.model.CategoryQuery;
import com.hskj.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

//@RestController
//@Controller
//@ResponseBody
@RestController
@RequestMapping("/api/category")
public class CategoryController {
    @Autowired
    private CategoryService service;

    @RequestMapping("/hello")
    public String Hello(){
//        int a=1/0;
//        if(1 == 1){
//            throw  new MyException(808,"数据报错服务异常！！");
//        }
        return "Hello SpringBoot";
    }
//    @GetMapping
//    public List<Category> findAll(){
//        return service.findAll();
//    }
    @GetMapping
    public List<Category> select(CategoryQuery query){
        List<Category> select = service.select(query);
        return select;
    }
//    @GetMapping("/find")
//    public ResponseDTO selectAll(CategoryQuery query){
//        List<Category> select = service.select(query);
//        return ResponseDTO.success(select);
//    }

    @PostMapping
    public Integer insert(@RequestBody Category category){
        return service.insert(category);
    }
    @PutMapping
    public Integer update(@RequestBody Category category){
        return service.update(category);
    }
    @DeleteMapping
    public Integer delete(Integer id){
        return service.delete(id);
    }
}
